package com.axt.manager.action;

import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.axt.manager.bean.AuthBean;
import com.axt.manager.model.Auth;
import com.axt.soa.action.BaseAction;
import com.axt.soa.msg.types.MsgParam;

public class AuthAction extends BaseAction{
	private AuthBean authBean = new AuthBean();
	private List<Auth> auths = null;
	
	private String authId;
	private String serverId;
	private String userId;
	
	@JSON(name="auths")
	public List<Auth> getAuths() {
		return auths;
	}
	public void setAuths(List<Auth> auths) {
		this.auths = auths;
	}
	
	@JSON(name="errcode")
	public int getErrcode() {
		return errcode;
	}
	
	@JSON(name="errinfo")
	public String getErrinfo() {
		return errinfo;
	}
	
	@JSON(name="authid")
    public String getAuthId() {
		return authId;
	}

	public String setAuthId() {
		return authId;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	//添加权限
	public String addAuth() throws Exception {
    	
		authBean.addAuth(authId, serverId, userId);
    	setErrcode(authBean.getErrcode());
		setErrinfo(authBean.getErrinfo());
		
    	return MsgParam.SUCCESS;
    }
	//获取权限列表
	public String queryAuths() throws Exception {
    	
		setAuths(authBean.queryAuthList());
    	setErrcode(authBean.getErrcode());
		setErrinfo(authBean.getErrinfo());
		
    	return MsgParam.SUCCESS;
    }
	// 删除节点
	public String deleteAuthById() throws Exception {
    	
		authBean.deleteAuth(authId);
    	setErrcode(authBean.getErrcode());
		setErrinfo(authBean.getErrinfo());
		
    	return MsgParam.SUCCESS;
    }
	// 删除节点
	public String deleteAuth() throws Exception {
    	
		authBean.deleteAuth(userId, serverId);
    	setErrcode(authBean.getErrcode());
		setErrinfo(authBean.getErrinfo());
		
    	return MsgParam.SUCCESS;
    }
}
